import Vue from 'vue'
import VueRouter from 'vue-router'
import routes from '@/router/routes'
import { getToken } from '@/utils/storgae'
Vue.use(VueRouter)

const router = new VueRouter({
  routes
})

const white = [
  '/login',
  '/register',
  '/homepage',
  '/my',
  '/particulars',
  '/find',
  '/contented'
]

router.beforeEach((to, from, next) => {
  const token = getToken()
  if (token) {
    next()
  } else {
    if (white.includes(to.path)) {
      next()
    } else {
      next('/login')
    }
  }
})

export default router
